﻿<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title>博烨脚本</title>
		<meta name="keywords" content="登录脚本" />
		<meta name="description" content="登录脚本" />
		<link rel="stylesheet" type="text/css" href="css/www.css">
	</head>

	<body>
		<div class="box">
			<h2 style="color:white">请登录并下载博烨脚本</h2>
			<input type="text" id="username" name="" placeholder="用户名">
			<input type="text" id="password" name="" placeholder="密码">
			<p>
				<button class="button" onclick="login(1)">下载</button>
			</p>
			<p>
				<button class="button" onclick="login(2)">使用</button>
			</p>
		</div>
		<script type="text/javascript" src="../js/public.js"></script>
		<script type="text/javascript" src="../js/jquery-2.1.1.js"></script>
		<script>
			$(document).keydown(function(e) {
				if(e.keyCode == 13) {
					login();
				}
			})

			function login(rese) {

				var username = $('#username').val();
				var password = $('#password').val();
				$.ajax({
					url: bulicUrl + 'class/classLogin.php',
					type: 'POST',
					dataType: 'json',
					data: {
						username: username,
						password: password
					},
					success: function(result) {
						console.log(result[6]);
						var tpo = timeDui(result[6]);

						if(result == 'nameerror') {
							alert('用户名不存在');
						} else if(result == "passerror") {
							alert("密码错误");
						} else {

							window.sessionStorage.setItem('userId', result[0]); //保存当前登录用户id用来判断是否是管理员
							window.sessionStorage.setItem('userName', result[3]);
							window.sessionStorage.setItem('scale', Number(result[7]));
							window.sessionStorage.setItem('condition', 0);
							if(tpo == true) {
								//代表下载
								if(rese == 1) {
									window.location.href = 'boye.crx';
								} else {
									window.location.href = 'https://www.tampermonkey.net/scripts.php?ext=dhdg';
								}
								/*window.location.href = 'https://www.tampermonkey.net/index.php?ext=dhdg';*/
							} else {
								alert("您已经到期，请续租！");
							}
						}
					},
					error: function(xhr, textStatus, errorThrown) {　　　　　　　　
						alert("登录未成功");　　　　
					}
				});
			}

			function timeDui(res) {
				var muqian = getTime();
				var jiezhi = res;
				mushu = getYearMonth(muqian);
				console.log(mushu);
				jieshu = getYearMonth(jiezhi);
				console.log(jieshu);
				//判断年
				if(Number(jieshu[0]) >= Number(mushu[0])) { //截止大于现在年
					//真
					if(Number(jieshu[0]) == Number(mushu[0])) { //年相同
						if(Number(jieshu[1]) >= Number(mushu[1])) { //截止大于等于
							if(Number(jieshu[1]) == Number(mushu[1])) {
								if(Number(jieshu[2]) >= Number(mushu[2])) {
									return true;

								} else {
									return false
								}
							} else {
								return true;
							}
						} else {

							return false
						}
					} else {
						return true;
					}
				} else {
					return false
				}
			}

			function getYearMonth(date) {
				// 将日期以空格隔开，即['2020-06-13', '17:10:09']
				date = (date + '').split(/[ ]+/);
				let result = [];
				let reg = /^(\d{4})年(\d{1,2})月(\d{1,2})日$/;
				// 用截取出来的年月日进行正则表达式匹配
				reg.exec(date[0]);
				result.push(RegExp.$1); //获取匹配到的第一个子匹配，即‘2020’
				result.push(RegExp.$2);
				result.push(RegExp.$3);
				return result;
			}

			function getcon() {
				alert("您已经到期，请续租！");
			}
		</script>
		<style>
			.button {
				width: 200px;
				padding: 8px;
				background-color: #f7f8f9;
				color: #428bca;
				text-align: center;
				vertical-align: middle;
				font-weight: 900;
				font-size: 125%
			}
			
			.button {
				border: groove 0.2em red;
				border-radius: 2em;
			}
			.button:hover {
				background-color: #2ecc71;
				color: white;
			}
		</style>
	</body>

</html>